$.ajax({
    url: '/my/user/userinfo',
  success: function (res) {
      // console.log(res);
      if (res.status === 0) {
        //设置昵称
       let name = res.data.nickname|| res.data.username
        $('.username').text(name)
        //设置头像
        if (res.data.user_pic) {
          $('.layui-nav-img').attr('src',res.data.user_pic).show()
        } else {
          //没有头像截取名字
          let first = res.data.username.substring(0,1).toUpperCase()
          $('.text-avater').text(first).css('display','inline-block')
        }
     }
  }
})

  //退出功能
$('#logout').on('click', function () {
  layer.confirm('确定要退出吗', function (index) {
    //移除token
    localStorage.removeItem('token')
    location.href = './login.html'
    //调用 关闭弹层layer.close(index)
    layer.close(index)
  })
})